_require local "../../../../basis.smi"
(* _require local "../../../data/symbols/main/Symbol.smi" *)
_require local "../../../extensions/debug/main/Bug.smi"

_require local "../../../compilerIRs/absyn/main/AbsynConst.smi"
_require local "../../../data/builtin/main/BuiltinTypes.smi"

_require "../../../../smlformat-lib.smi"
_require "../../../data/symbols/main/Loc.smi"
_require "../../../extensions/usererror/main/UserError.ppg.smi"
_require "../../../data/types/main/Types.ppg.smi"
_require "../../../compilerIRs/typedcalc/main/TypedCalc.ppg.smi"
_require "../../../compilerIRs/typedcalc/main/TypedCalcUtils.smi"
_require "./MatchData.smi"

structure MatchError = 
struct
  val format_flag
      : int ref -> SMLFormat.FormatExpression.expression list
      
  type rule
    = (TypedCalc.tppat list * TypedCalc.tpexp) * int ref
  val format_rule
      : rule -> SMLFormat.FormatExpression.expression list

  exception MatchError of string * rule list

  val bindRedundantMessage : string
  val bindNotExhaustiveMessage : string
  val bindBothMessage : string
  val matchRedundantMessage : string
  val matchNotExhaustiveMessage : string
  val matchBothMessage : string

  val raiseBindFailExp
      : Types.ty -> Loc.loc -> TypedCalc.tpexp
  val raiseMatchFailExp
      : Types.ty -> Loc.loc -> TypedCalc.tpexp
  val handleFail
      : Types.varInfo -> Types.ty -> Loc.loc -> TypedCalc.tpexp
  val raiseMatchCompBugExp
      : Types.ty -> Loc.loc -> TypedCalc.tpexp

  datatype flagKind = Redundant | NotExhaustive

  val clearErrorMessages
      : unit -> unit
  val putErrorMessage
      : Loc.loc * UserError.errorKind * string * rule list -> unit
  val getErrorMessages
      : unit -> UserError.errorInfo list
  val clearFlag
      : flagKind -> unit
  val setFlag
      : flagKind -> unit
  val isRedundant
      : unit -> bool
  val isNotExhaustive
      : unit -> bool

  val haveRedundantRules
      : ('a * bool ref) list -> bool
(*
  val print
      : SMLFormat.FormatExpression.expression list -> string
*)
  val insertNewline
      : string list -> string
  val checkError
      : MatchData.kind * bool * bool * rule list * Loc.loc -> unit

end
